﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Radar.Navigation;

namespace Radar.Optimization
{
    internal class GridCellRange
    {

        internal GridCellRange(GridCell[,] cells)
        {
            Cells = cells;
            Width = Cells.GetLength(0);
            Height = Cells.GetLength(1);
            Count = Width * Height;
        }

        public NavZone[] GetZonesStarting()
        {
            List<NavZone> zones = new List<NavZone>();
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    NavZone[] zonesInCell = Cells[x, y].ZonesStarting;
                    int zoneCount = zonesInCell.Length;
                    for (int i = 0; i < zoneCount; i++)
                    {
                        zones.Add(zonesInCell[i]);
                    }
                }
            }
            return zones.ToArray();
        }

        public NavZone[] GetZonesTouching()
        {
            List<NavZone> zones = new List<NavZone>();
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    NavZone[] zonesInCell = Cells[x, y].ZonesTouching;
                    int zoneCount = zonesInCell.Length;
                    for (int i = 0; i < zoneCount; i++)
                    {
                        NavZone zone = zonesInCell[i];
                        if (!zones.Contains(zone)) zones.Add(zone);
                    }
                }
            }
            return zones.ToArray();
        }

        public int Width;

        public int Height;

        public int Count;

        public GridCell[,] Cells;

    }
}
